package edu.uwosh.cs342.project4;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper{

	public static final String DB_NAME = "user_favorites.db";
	public static final int VERSION = 1;
	public static final String TABLE_NAME = "favorites";
	public static final String F_NAME = "name";
	public static final String F_LAT = "lat";
	public static final String F_LONG = "long";
	
	public DBHelper(Context context) {
		super(context, DB_NAME, null, VERSION);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String dbCreate = String.format("create table %s(%s TEXT primary key, %s INTEGER, %s INTEGER)",
				TABLE_NAME, F_NAME, F_LAT, F_LONG);
		db.execSQL(dbCreate);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("drop table if exists " + TABLE_NAME);
		onCreate(db);
		
	}
	
	public void insertFavorite(SQLiteDatabase db, ContentValues cv) {
		db.insert(TABLE_NAME, null, cv);
	}
}
